package com.office.forum.manage.comments.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.office.forum.manage.comments.domain.ForumComments;
import com.office.forum.manage.comments.domain.ProcessComments;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.office.common.annotation.Log;
import com.office.common.core.controller.BaseController;
import com.office.common.core.domain.AjaxResult;
import com.office.common.enums.BusinessType;
import com.office.forum.manage.comments.service.IForumCommentsService;
import com.office.common.core.page.TableDataInfo;

/**
 * 论坛评论Controller
 * 
 * @author ruoyi
 * @date 2025-05-17
 */
@RestController
@RequestMapping("/system/comments")
public class ForumCommentsController extends BaseController
{
    @Autowired
    private IForumCommentsService forumCommentsService;

    /**
     *
     * @param id 用户id
     * @return 该用户的头像
     */
    @GetMapping("/avatar/{id}")
    public AjaxResult getAvatarById(@PathVariable Long id){
        String avatar = forumCommentsService.getAvatarByUserId(id);
        return AjaxResult.success(avatar);
    }

    /**
     * 查询论坛评论列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ForumComments forumComments)
    {
        startPage();
        List<ForumComments> list = forumCommentsService.selectForumCommentsList(forumComments);
        return getDataTable(list);
    }


    /**
     * 获取论坛评论详细信息
     */
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return success(forumCommentsService.selectForumCommentsByCommentId(commentId));
    }

    /**
     * 新增论坛评论
     */
    @Log(title = "论坛评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForumComments forumComments)
    {
        return toAjax(forumCommentsService.insertForumComments(forumComments));
    }

    /**
     * 修改论坛评论
     */
    @Log(title = "论坛评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForumComments forumComments)
    {
        return toAjax(forumCommentsService.updateForumComments(forumComments));
    }

    /**
     * 删除论坛评论
     */
    @Log(title = "论坛评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(forumCommentsService.deleteForumCommentsByCommentIds(commentIds));
    }

    /**
     * 实现建立树状评论
     */
//    @PreAuthorize("@ss.hasPermi('system:comments:treeList')")
    @GetMapping("/treeList")
    public TableDataInfo treeList(ForumComments forumComments)
    {
        startPage();
        List<ForumComments> list = forumCommentsService.selectForumCommentsList(forumComments);
        ProcessComments.processComments(list);
        return getDataTable(list);
    }
    /**
     * 用户id查询论坛评论列表
     */
    @GetMapping("/commentsList")
    public TableDataInfo userList(ForumComments forumComments)
    {
        startPage();
        Long userId = forumComments.getUserId();
        List<ForumComments> list = forumCommentsService.selectForumCommentsByUserId(userId);
        return getDataTable(list);
    }
}
